Add clean if-file-deleted setting - #90
Conversation
augustjk
left a comment
There was a problem hiding this comment.
Found some residuals from CacheKey refactor and have a question about the behavior for considering input files of dependents noted in the test.
| wireitConfig.clean !== true && | ||
| wireitConfig.clean !== false && | ||
| wireitConfig.clean !== 'if-file-deleted' |
There was a problem hiding this comment.
Not sure if actionable, wondering if this should all be the same type? All strings instead of a bool and string combo.
There was a problem hiding this comment.
I considered "always" and "never" instead of true and false. Somehow "never" feels stronger than false, and the potentially confusing thing is that we actually always do a clean build when restoring from cache. I'm not sure.
There was a problem hiding this comment.
"on", "off"? or "enabled", "disabled"?
There was a problem hiding this comment.
"on", "off"? or "enabled", "disabled"?
Those seem semantically equivalent to true and false, but I feel like it might be harder to remember those strings over true and false.
Adds a new option for the
cleansetting calledif-file-deleted. In this mode, we cleanoutputfiles if any of the inputfileshave been deleted since the previous run.This is useful for commands like
tsc --build:(the default) is not a good option for TypeScript, because it either eliminates the benefits of incremental compilation, or causes your"clean": true.tsbuildinfoto get out of sync, depending on whether you include your.tsbuildinfofile in theoutputarray.is also not a good option for TypeScript, because it causes stale outputs to accumulate. This is because when you delete or rename a"clean": false.tssource file,tscitself does not automatically delete the corresponding.jsfile emitted by previous compiles."clean": "if-file-deleted"is a nice balance between fast and correct output. It lets you usetscfast incremental compiles when a.tssource file is added or modified, but a clean build when a.tssource file is deleted.Example
{ "scripts": { "ts": "wireit", }, "wireit": { "ts": { "command": "tsc --build --pretty", "clean": "if-file-deleted", "files": [ "src/**/*.ts", "tsconfig.json" ], "output": [ "lib/**", ".tsbuildinfo" ] } }Fixes #70
Also
Renames
CacheKeytoScriptState. I think this is a more clear name, because this data type is used for purposes other than caching (e.g. checking freshness, and now also for comparing input file names). It also maps more closely to the existing.wireit/<script>/statefile, which is where we serialize state.Some refactoring to
ScriptState. We previously did not save anyScriptStateat all when a script was uncacheable, and used a specialUNCACHEABLEsentinel to represent that case. However, this meant that we had no record of the previous input files in the case where a script was uncacheable, which we now need. We now instead always write a state file, and set anuncacheableproperty on it.Added a "Recipes" section to the README, for tool-specific guidance. Starting with TypeScript, since that was the motivation for this change.